using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;

namespace SettingsView.Search
{
	internal class DirectoryTree : INotifyPropertyChanged
	{
		private bool _IsExpanded;

		private bool _IsSelected;

		private ObservableCollection<DirectoryTree> dirs;

		public bool IsExpanded
		{
			get
			{
				return _IsExpanded;
			}
			set
			{
				if (_IsExpanded != value)
				{
					_IsExpanded = value;
				}
			}
		}

		public bool IsSelected
		{
			get
			{
				return _IsSelected;
			}
			set
			{
				if (_IsSelected != value)
				{
					_IsSelected = value;
				}
			}
		}

		public DirectoryInfo Info { get; set; }

		public DirectoryTree Parent { get; set; }

		public ObservableCollection<DirectoryTree> Directories
		{
			get
			{
				if (dirs == null)
				{
					try
					{
						DirectoryInfo[] directories = Info.GetDirectories();
						if (directories.Length > 0)
						{
							dirs = new ObservableCollection<DirectoryTree>();
							DirectoryInfo[] array = directories;
							foreach (DirectoryInfo di in array)
							{
								dirs.Add(new DirectoryTree(this, di));
							}
						}
					}
					catch (UnauthorizedAccessException)
					{
					}
				}
				return dirs;
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;

		public DirectoryTree()
		{
		}

		public DirectoryTree(DirectoryTree parent, DirectoryInfo di)
			: this()
		{
			Parent = parent;
			Info = di;
		}

		public static ObservableCollection<DirectoryTree> InitRoot()
		{
			ObservableCollection<DirectoryTree> observableCollection = new ObservableCollection<DirectoryTree>();
			string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
			DirectoryTree item = new DirectoryTree(null, new DirectoryInfo(folderPath));
			observableCollection.Add(item);
			DriveInfo[] drives = DriveInfo.GetDrives();
			DriveInfo[] array = drives;
			foreach (DriveInfo driveInfo in array)
			{
				if (driveInfo.DriveType == DriveType.Fixed)
				{
					DirectoryTree item2 = new DirectoryTree(null, driveInfo.RootDirectory);
					observableCollection.Add(item2);
				}
			}
			return observableCollection;
		}

		private void NotifyPropertyChanged(string info)
		{
			if (this.PropertyChanged != null)
			{
				this.PropertyChanged(this, new PropertyChangedEventArgs(info));
			}
		}
	}
}
